// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.pages.tapbb;

import java.util.Date;
import java.util.List;

import lichen.entities.forum.Forum;
import lichen.entities.forum.ForumImpl;
import lichen.pages.base.BasePage;
import lichen.pages.base.LogInfoPage;

/**
 * 论坛的phpbb3风格首页面
 * 
 * @author <a href="mailto:tapestry5@gmail.com">Jim</a>
 * @version $Revision: 147 $
 * @since 0.0.1
 */
public class Home extends BasePage implements LogInfoPage {
	public void setupRender() {
		System.out.println("test");
	}

	public Date getCurrentTime() {
		return new Date();
	}

	// 查询一级论坛,1 为论坛的大类，2 为顶级论坛.
	private static final String QUERY_FORUM_HQL = "from "
			+ ForumImpl.class.getName() + " f where " + "f."
			+ ForumImpl.DEPTH_PRO_NAME + " <3 " + "and f."
			+ ForumImpl.LEFT_PRO_NAME + ">? " + "and f."
			+ ForumImpl.RIGHT_PRO_NAME + "<?";

	private static final String QUERY_CATEGORY_HQL = "from "
			+ ForumImpl.class.getName() + " f where f."
			+ ForumImpl.DEPTH_PRO_NAME + " =1";

	// 循环中使用的变量
	private Forum forum;

	// 循环中适用的变量
	private Forum category;

	/**
	 * 查询所有的论坛.
	 * 
	 * @return 论坛列表.
	 */
	public List getForums() {
		return this.getEntityService().find(
				QUERY_FORUM_HQL,
				new Object[] { this.category.getLeft(),
						this.category.getRight() });
	}

	/**
	 * @return Returns the forum.
	 */
	public Forum getForum() {
		return forum;
	}

	/**
	 * @param forum
	 *            The forum to set.
	 */
	public void setForum(Forum forum) {
		this.forum = forum;
	}

	public List getCategories() {
		return this.getEntityService().find(QUERY_CATEGORY_HQL);
	}

	/**
	 * @return Returns the category.
	 */
	public Forum getCategory() {
		return category;
	}

	/**
	 * @param category
	 *            The category to set.
	 */
	public void setCategory(Forum category) {
		this.category = category;
	}

	public String getLogInfo() {
		return this.getMessages().get("view-home-page");
	}
}
